home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7560 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: String Encryption
  5. Date: 25 Feb 1996 13:21:57 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gqjtlINNb75@keats.ugrad.cs.ubc.ca>
  8. References: <1996Feb21.101532.15110@es.dupont.com> <1996Feb21.174407.20730@newshost.micro.ti.com> <4ghq1u$sed@hpbblb.bbn.hp.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4ghq1u$sed@hpbblb.bbn.hp.com>, Matthias Dittrich  <matti> wrote:
  12. >brett@racerx.micro.ti.com (Brett L. Huber) wrote:
  13. >>Malcolm Smart (MALCOLM.SMART@CONOCO.DUPONT.COM) wrote:
  14. >>> Has anybody out there got any small routines that I can apply to strings 
  15. >>> which will effectively encrypt them (and decrypt!).  It's not a matter of 
  16. >>> state security so it doesn't have to be that secure, just make it 
  17. >>> unreadable.  
  18. >>
  19. >>It really depends on what level of "unreadability" you want.  Who are
  20. >>you protecting the data from?  If you aren't protecting a secret, try
  21. >>"rot13," which translates A->N, B->O, ... Z->M.
  22. >>
  23. >>For an introduction to cryptographic techniques, try the sci.crypt FAQ:
  24. >>http://www.cis.ohio-state.edu/hypertext/faq/bngusenet/sci/crypt/top.html
  25. >>
  26. >> ...
  27. >You also can use the crypt() function (see man 3 crypt).
  28.  
  29. This function is technically a one-way hash, not an encryption, which is what
  30. is called for in the above request.
  31.  
  32. I think that what the poster wants could be satsified by a translation table
  33. which matches each printable character to a unique printable character. Such a
  34. one-to-one and onto mapping is naturally invertible. Rot13 is just one such
  35. possiblity, though I don't know how it deals with digits and other symbols.
  36.  
  37. By the way, this kind of translation can be done by the UNIX utility "tr". If
  38. you have that available, why bother writing a C program? For example, to
  39. do ROT13 on upper and lower-case letters, you pipe through:
  40.  
  41.     tr [A-Za-z] [N-ZA-Mn-za-m]
  42.  
  43. The first argument specifies the table of source characters, in a compact form
  44. resembling regex character classes. The second argument specifies the
  45. destination table.
  46.  
  47. In this case, the same command encrypts and decrypts, since Rot13 is
  48. its own inverse.
  49. -- 
  50.  
  51.